<template>
  <div>
    <center>
      <b-tooltip label="展开回复" dashed>
        <b-button
          v-if="!info"
          icon-left="chevron-triple-down"
          size="is-large"
          type="is-primary"
          @click="info = true"
        >
        </b-button>
      </b-tooltip>
    </center>
    <br />
    <div class="columns is-multiline is-mobile" v-if="info">
      <div v-for="item in replys" :key="item" class="column is-half">
        <div class="card">
          <header class="card-header">
            <p class="card-header-title">
              {{ item.title.String }}
            </p>
            <button class="card-header-icon" aria-label="more options" @click="delReply(item.rid)" v-if="userLevel()">
              <i class="delete" aria-hidden="true"></i>
            </button>
            <!-- <button class="card-header-icon" aria-label="more options">
      <span class="icon">
        <i class="fas fa-angle-down" aria-hidden="true"></i>
      </span>
    </button> -->
          </header>
          <div class="card-content">
            <div class="content">
              {{ item.text.String }}
            </div>
          </div>
          <footer class="card-footer">
            <a href="#" class="card-footer-item">{{ item.username.String }}</a>
            <a href="#" class="card-footer-item">
              <time datetime="2016-1-1" style="float: right">
                {{ item.date.Time | dateformat("YYYY年MM月DD日") }}
              </time>
            </a>
            <!-- <a href="#" class="card-footer-item">Delete</a> -->
          </footer>
        </div>
        <div style="padding: 5px"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      replys: [],
      info: false,
    };
  },
  methods: {
    userLevel(){
      if(localStorage.getItem("level") == 'admin' || localStorage.getItem("level") == 'root'){
        return true
      }
      return false
    },
    //删除评论
    async delReply(replyid){
      let res = await this.$http.delete("/go/reply/delByRid/"+replyid,{
        headers: {
          pass: "",
          Authorization: "Bearer " + localStorage.getItem("token"),
        },
      })
      if(res.data.status == 20000){
        this.$vs.notification({
          title: "删除成功",
        });
        this.replys = this.replys.filter(function (value, index, arr) {
          return value.rid != replyid;
        });
      }
    }
  },
  async beforeCreate() {
    let res = await this.$http.get(
      "/go/reply/viewByGid/" + (await this.$parent.getGid()),
      {
        headers: {
          pass: "",
          Authorization: "Bearer " + localStorage.getItem("token"),
        },
      }
    );
    console.log(res.data);
    this.replys = res.data.data;
  },
};
</script>

<style>
</style>